package com.gl.blank.jarservices.util;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.access.SingletonBeanFactoryLocator;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ServicesContextSingletonBeanFactoryLocator extends SingletonBeanFactoryLocator
{
    protected ServicesContextSingletonBeanFactoryLocator(String resourceLocation)
    {
        super(resourceLocation);
    }

    @Override
    protected BeanFactory createDefinition(String resourceLocation, String factoryKey)
    {
        final ClassPathXmlApplicationContext cpxac = new ClassPathXmlApplicationContext(
            new String[] { resourceLocation }, false);
        final ClassLoader classLoader = this.getClass().getClassLoader();
        cpxac.setClassLoader(classLoader);
        return cpxac;
    }

    public static BeanFactory getServicesBeanFactory()
    {
        return getInstance().useBeanFactory("servicesContext").getFactory();
    }
}
